package com.fsbm.ctech.maxis.ebpsbackend;

//import com.fsbm.ctech.controller.*;
import com.checkfree.isolutions.admin.ObjectId;

import java.awt.Color;
import java.io.*;
import java.util.*;
import java.text.*;

import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPageEvent;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Chunk;
import com.lowagie.text.Font;
import com.lowagie.text.Phrase;
import com.lowagie.text.Element;
import com.lowagie.text.Image;
import com.lowagie.text.Rectangle;

import com.checkfree.isolutions.persist.PersistServer;
import com.checkfree.isolutions.statement.*;
import com.checkfree.isolutions.statement.persist.*;
import com.checkfree.isolutions.streaming.IClassId;



public class PDFServlet_v3r00 extends PdfPageEventHelper{

	/**
	 * Constructor
	 */
    public PDFServlet_v3r00() {

        try {


        } catch (Exception e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        String strStmtId="";

        for ( int i = 0; i < args.length; i++ ) {
            if (args[i].toLowerCase().indexOf("-stmtid") !=-1)
            {
                String buffer = args[i];
                int pos = buffer.indexOf("=");
                strStmtId = buffer.substring(pos+1);
                continue;
            }
        }

        // Execute program
        //PDFServlet_v3r00 pdf = new PDFServlet_v3r00();
        //pdf.StatementGeneration(strStmtId);

    }

    public void StatementGeneration(String strStmtId,String pdfFileName) {
        try {

        	//PersistServer.activate();
        	//PersistServer.beginTransaction();

            StatementHome home = StatementHomeImpl.singleton();
            int statementId = Integer.parseInt(strStmtId);
            ObjectId objectId = new ObjectId(IClassId.STATEMENT, statementId);
            Statement cfiStatement   = home.findByObjectId(objectId);

           	//Get section from root section
           	final StatementSection cfiRootSection = cfiStatement.getRootSection();
		   	final StatementSection cfiSummarySection = cfiRootSection.getSection("SummarySection");
		   	final StatementSection cfiBillingPeriodSection = cfiRootSection.getSection("BillingPeriodSection");
			final StatementSection cfiDepositPaidSection = cfiRootSection.getSection("DepositPaidSection");
			final StatementSection cfiCreditLimitSection = cfiRootSection.getSection("CreditLimitSection");
			final StatementSection cfiImportantMessagesSection = cfiRootSection.getSection("ImportantMessagesSection");
			final StatementSection cfiCurrentPromotionSection = cfiRootSection.getSection("CurrentPromotionSection");

			//Get section from summary section
		   	final StatementSection cfiRegistrationChargesSection = cfiSummarySection.getSection("RegistrationChargesSection");
		   	final StatementSection cfiMonthlyChargesSection = cfiSummarySection.getSection("MonthlyChargesSection");
		   	final StatementSection cfiValueAddedServicesSection = cfiSummarySection.getSection("ValueAddedServicesSection");
		   	final StatementSection cfiUsageChargesSection = cfiSummarySection.getSection("UsageChargesSection");
		   	final StatementSection cfiServiceTaxSection = cfiSummarySection.getSection("ServiceTaxSection");
		   	final StatementSection cfiOtherChargesSection = cfiSummarySection.getSection("OtherChargesSection");
		   	final StatementSection cfiDiscountSection = cfiSummarySection.getSection("DiscountSection");

			//Get data field from root section
			final String AccNo = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("AccountNumber"));
			final String StmtDt = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("StatementDate"));
			final String AccName = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("AccountName"));
		  	final String TotalAmountDue = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("TotalAmountDue"));

			// Added by Meau for rounding
		  	String TotalAmount = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("TotalAmount"));

			// end added by Meau for rounding

		  	final String PhoneNo = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("PhoneNumber"));
		  	final String RefNo = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("ReferenceNumber"));
		  	final String CurrentChargesDueDate = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("CurrentChargesDueDate"));
		  	final String Address1 = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("Address1"));
		  	final String Address2 = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("Address2"));
		  	final String Address3 = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("Address3"));
		  	final String Address4 = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("Address4"));
		  	final String MarketSegment = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("MarketSegment"));
		  	final String OldAccountNumber = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("OldAccountNumber"));

		  	//Get data field from billing period section
		  	String BillPeriod = "";
		  	if(cfiBillingPeriodSection!=null){
				BillPeriod = EbppxUtil.htmlEncode(cfiBillingPeriodSection.getFieldText("BillingPeriod"));
			}

		  	//Get data field from deposit paid section
		  	String DepositPaid = "";
		  	if(cfiDepositPaidSection!=null){
				DepositPaid = EbppxUtil.htmlEncode(cfiDepositPaidSection.getFieldText("DepositPaid"));
			}

		  	//Get data field from credit limit section
		  	String CreditLimit = "";
		  	if(cfiCreditLimitSection!=null){
				CreditLimit = EbppxUtil.htmlEncode(cfiCreditLimitSection.getFieldText("CreditLimit"));
			}

		  	//Get data field from Summary section
		  	final String PreviousBalance = EbppxUtil.htmlEncode(cfiSummarySection.getFieldText("PreviousBalance"));
		  	final String PaymentReceived = EbppxUtil.htmlEncode(cfiSummarySection.getFieldText("PaymentReceived"));
		  	final String Adjustment = EbppxUtil.htmlEncode(cfiSummarySection.getFieldText("Adjustment"));
		  	final String BalanceForward = EbppxUtil.htmlEncode(cfiSummarySection.getFieldText("BalanceForward"));
		  	final String TotalCurrentCharges = EbppxUtil.htmlEncode(cfiSummarySection.getFieldText("TotalCurrentCharges"));

		  	//Get data field from registration charges section
		  	String RegistrationCharges = "";
		  	if(cfiRegistrationChargesSection!=null){
				RegistrationCharges = EbppxUtil.htmlEncode(cfiRegistrationChargesSection.getFieldText("Amount"));
			}

		  	//Get data field from usage charges section
		  	String UsageCharges = "";
		  	if(cfiUsageChargesSection!=null){
				UsageCharges = EbppxUtil.htmlEncode(cfiUsageChargesSection.getFieldText("Amount"));
			}

		  	//Get data field from monthly charges section
		  	String MonthlyCharges = "";
		  	if(cfiMonthlyChargesSection!=null){
				MonthlyCharges = EbppxUtil.htmlEncode(cfiMonthlyChargesSection.getFieldText("Amount"));
			}

			//Get data field from service tax section
			String ServiceTax = "";
			if(cfiServiceTaxSection!=null){
				ServiceTax = EbppxUtil.htmlEncode(cfiServiceTaxSection.getFieldText("Amount"));
			}

			//Get data field from value added services section
			String ValueAddedServices = "";
			if(cfiValueAddedServicesSection!=null){
				ValueAddedServices = EbppxUtil.htmlEncode(cfiValueAddedServicesSection.getFieldText("Amount"));
			}

			//Get data field from other charges section
			String otherCharges = "";
			if(cfiOtherChargesSection!=null){
				otherCharges = EbppxUtil.htmlEncode(cfiOtherChargesSection.getFieldText("Amount"));
			}

			//Get data field from discount section
			String discount = "";
			if(cfiDiscountSection!=null){
				discount = EbppxUtil.htmlEncode(cfiDiscountSection.getFieldText("Amount"));
			}

			String MessageLine1 = "";
			String MessageLine2 = "";
			String MessageLine4 = "";
			String MessageLine5 = "";
			String MessageLine6 = "";
			String MessageLine8 = "";
			String MessageLine10 = "";
			String MessageLine12 = "";
			String MessageLine13 = "";
			String MessageLine14 = "";
			String MessageLine16 = "";
			String MessageLine17 = "";
			String MessageLine18 = "";
			if(cfiImportantMessagesSection!=null){
				//Get data field from important messages section
				MessageLine1 = EbppxUtil.htmlEncode(cfiImportantMessagesSection.getFieldText("MessageLine1"));
				MessageLine2 = EbppxUtil.htmlEncode(cfiImportantMessagesSection.getFieldText("MessageLine2"));
				MessageLine4 = EbppxUtil.htmlEncode(cfiImportantMessagesSection.getFieldText("MessageLine4"));
				MessageLine5 = EbppxUtil.htmlEncode(cfiImportantMessagesSection.getFieldText("MessageLine5"));
				MessageLine6 = EbppxUtil.htmlEncode(cfiImportantMessagesSection.getFieldText("MessageLine6"));
				MessageLine8 = EbppxUtil.htmlEncode(cfiImportantMessagesSection.getFieldText("MessageLine8"));
				MessageLine10 = EbppxUtil.htmlEncode(cfiImportantMessagesSection.getFieldText("MessageLine10"));
				MessageLine12 = EbppxUtil.htmlEncode(cfiImportantMessagesSection.getFieldText("MessageLine12"));
				MessageLine13 = EbppxUtil.htmlEncode(cfiImportantMessagesSection.getFieldText("MessageLine13"));
				MessageLine14 = EbppxUtil.htmlEncode(cfiImportantMessagesSection.getFieldText("MessageLine14"));
				MessageLine16 = EbppxUtil.htmlEncode(cfiImportantMessagesSection.getFieldText("MessageLine16"));
				MessageLine17 = EbppxUtil.htmlEncode(cfiImportantMessagesSection.getFieldText("MessageLine17"));
				MessageLine18 = EbppxUtil.htmlEncode(cfiImportantMessagesSection.getFieldText("MessageLine18"));
			}

			//Padding Amount
			int tpPadBottom = 8;
			int tpPadTop = 3;
			int tpPadRight = 8;
			int tpPadLeft = 8;

			final Date dtVal = cfiStatement.getDate();
            final DateFormat dfdisp = new SimpleDateFormat("ddMMMyyyy");
            String stdate = EbppxUtil.htmlEncode(dfdisp.format(dtVal));

            String filename = new String(strStmtId+"-"+stdate);
           	filename += ".pdf";

           	String OutPath = "D://";

		    //	ServletResponse response;
			//response.setContentType("application/pdf");
		   	//response.setHeader("Content-Disposition","attachment; filename=" + filename);

	   		Document document = new Document();

	   		PdfWriter writer = null;

	   	    writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFileName));

	   		// this will activate the method OnOpenDocument(), OnCloseDocument() and OnEndPage()
            writer.setPageEvent(this);

	   		document.open();

				//Write data to PDF

                //Crate Main Table for page position purpose
                float[] tableColsWidth = {4f, 2f};
                PdfPTable table = new PdfPTable(tableColsWidth);

                //set the table width percentage of the page
                table.setWidthPercentage(100);

				//Declare
				Chunk chunk;
				Phrase phrase;
				Paragraph paragraph;
				PdfPCell cell;
				Font font = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL,new Color(0, 0, 0));
				Font fontItalic = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.ITALIC,new Color(0, 0, 0));
				Font fontBold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD,new Color(0, 0, 0));
				Font fontSpace = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL,new Color(0, 0, 0));
				Font bigFontItalic = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC,new Color(0, 0, 0));
				Font bigFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD,new Color(0, 0, 0));

				//Title
				phrase = new Phrase();
				chunk = new Chunk("STATEMENT OF ACCOUNT\n", bigFontBold);
				phrase.add(chunk);
				chunk = new Chunk("PENYATA AKAUN", bigFontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
				cell.setColspan(2);
				cell.setBorderWidth(0);
				table.addCell(cell);

				//Account Name
				phrase = new Phrase();
				chunk = new Chunk("Account Name / ", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Nama Akaun : ", fontItalic);
				phrase.add(chunk);
				chunk = new Chunk(AccName, fontBold);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(2);
				cell.setBorderWidth(0);
				table.addCell(cell);

				//Add blank row
				cell = new PdfPCell(new Phrase("",fontBold));
				cell.setColspan(2);
				cell.setBorderWidth(0);
				table.addCell(cell);

				//Crate sub Table inside main table
                float[] subTableColsWidth = {3f, 4f, 2f, 3f};
                PdfPTable subTable = new PdfPTable(subTableColsWidth);

				//sub table header1
				phrase = new Phrase();
				chunk = new Chunk("Previous Balance\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Baki Dahulu ", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				subTable.addCell(cell);

				//sub table header2
				phrase = new Phrase();
				chunk = new Chunk("Payment Received\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Jumlah Bayaran Diterima ", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				subTable.addCell(cell);

				//sub table header3
				phrase = new Phrase();
				chunk = new Chunk("Adjustments\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Penyelarasan ", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				subTable.addCell(cell);

				//sub table header4
				phrase = new Phrase();
				chunk = new Chunk("Balance Forward\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Baki Ke Hadapan ", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				subTable.addCell(cell);

				//sub table Previous Balance
				phrase = new Phrase();
				chunk = new Chunk(PreviousBalance, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//sub table Payment Received
				phrase = new Phrase();
				chunk = new Chunk(PaymentReceived, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//sub table Adjustment
				phrase = new Phrase();
				chunk = new Chunk(Adjustment, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//sub table Balance Forward
				phrase = new Phrase();
				chunk = new Chunk(BalanceForward, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//add big blank row at sub table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(4);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//Current charges Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Current Charges\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Caj Semasa", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(3);
                cell.setBorderWidth(0);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				subTable.addCell(cell);

				//Current charges Content at sub table
				phrase = new Phrase();
				chunk = new Chunk(TotalCurrentCharges, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//add blank row at sub table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(4);
				subTable.addCell(cell);

				//Current charges due date Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Current Charges Due Date\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Tarikh Akhir Bayaran Caj Semasa", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(3);
                cell.setBorderWidth(0);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				subTable.addCell(cell);

				//Current charges due date Content at sub table
				phrase = new Phrase();
				chunk = new Chunk(CurrentChargesDueDate, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//add blank row at sub table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(4);
				subTable.addCell(cell);
/////////////////// Added by Meau for rounding/////////////////////////////////////////
				if(TotalAmount!=null && !TotalAmount.equals("")){
					//Total amount Title at sub table
					phrase = new Phrase();
					chunk = new Chunk("Total amount \n", fontBold);
					phrase.add(chunk);
					chunk = new Chunk("Jumlah", fontItalic);
					phrase.add(chunk);
                	cell = new PdfPCell(phrase);
                	cell.setColspan(3);
                	cell.setBorderWidth(0);
					cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
					subTable.addCell(cell);

					//Total amount due Content at sub table
					phrase = new Phrase();
					chunk = new Chunk(TotalAmount, font);
					phrase.add(chunk);
                	cell = new PdfPCell(phrase);
					cell.setHorizontalAlignment(Element.ALIGN_CENTER);
					cell.setPaddingTop(tpPadTop);
					cell.setPaddingBottom(tpPadBottom);
					subTable.addCell(cell);

					//add blank row at sub table
					cell = new PdfPCell(new Phrase("",fontSpace));
					cell.setBorderWidth(0);
					cell.setColspan(4);
					cell.setPaddingTop(tpPadTop);
					cell.setPaddingBottom(tpPadBottom);
					subTable.addCell(cell);
				}

				//Total amount due Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Total amount due\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Jumlah Perlu Dibayar", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(3);
                cell.setBorderWidth(0);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				subTable.addCell(cell);

				//Total amount due Content at sub table
				phrase = new Phrase();
				chunk = new Chunk(TotalAmountDue, fontBold);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//add blank row at sub table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(4);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//Account Summary Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Account Summary\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Ringkasan Akaun", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(3);
                cell.setBorder(PdfPCell.RIGHT + PdfPCell.BOTTOM);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				subTable.addCell(cell);

				//Amount Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Amount (RM)\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Amaun (RM)", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setPaddingLeft(tpPadLeft);
                cell.setBorder(PdfPCell.BOTTOM);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				subTable.addCell(cell);

				//Balance Forward Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Balance Forward\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Baki Ke Hadapan", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(3);
                cell.setBorder(PdfPCell.RIGHT + PdfPCell.BOTTOM);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				subTable.addCell(cell);

				//Balance Forward Amount at sub table
				phrase = new Phrase();
				chunk = new Chunk(BalanceForward, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setPaddingRight(tpPadRight);
                cell.setBorder(PdfPCell.BOTTOM);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				subTable.addCell(cell);

				//Registration Charges Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Registration Charges", font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
                cell.setBorderWidth(0);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Registration Charges Content at sub table
				phrase = new Phrase();
				chunk = new Chunk(RegistrationCharges, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setBorder(PdfPCell.RIGHT);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setPaddingRight(tpPadRight);
				subTable.addCell(cell);

				//Blank Column for Amount Section at sub table
                cell = new PdfPCell(new Phrase("",font));
                cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Monthly Charges Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Monthly Charges", font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
                cell.setBorderWidth(0);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Registration Charges Content at sub table
				phrase = new Phrase();
				chunk = new Chunk(MonthlyCharges, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setBorder(PdfPCell.RIGHT);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setPaddingRight(tpPadRight);
				subTable.addCell(cell);

				//Blank Column for Amount Section at sub table
                cell = new PdfPCell(new Phrase("",font));
                cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Value Added Services Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Value Added Services", font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
                cell.setBorderWidth(0);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Value Added Services Content at sub table
				phrase = new Phrase();
				chunk = new Chunk(ValueAddedServices, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setBorder(PdfPCell.RIGHT);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setPaddingRight(tpPadRight);
				subTable.addCell(cell);

				//Blank Column for Amount Section at sub table
                cell = new PdfPCell(new Phrase("",font));
                cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Usage Charges Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Usage Charges", font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
                cell.setBorderWidth(0);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Usage Charges Content at sub table
				phrase = new Phrase();
				chunk = new Chunk(UsageCharges, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setBorder(PdfPCell.RIGHT);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setPaddingRight(tpPadRight);
				subTable.addCell(cell);

				//Blank Column for Amount Section at sub table
                cell = new PdfPCell(new Phrase("",font));
                cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Other Charges Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Other Charges", font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
                cell.setBorderWidth(0);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Other Charges Content at sub table
				phrase = new Phrase();
				chunk = new Chunk(otherCharges, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setBorder(PdfPCell.RIGHT);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setPaddingRight(tpPadRight);
				subTable.addCell(cell);

				//Blank Column for Amount Section at sub table
                cell = new PdfPCell(new Phrase("",font));
                cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Discount & Rebates Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Discount & Rebates", font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
                cell.setBorderWidth(0);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Discount & Rebates Content at sub table
				phrase = new Phrase();
				chunk = new Chunk(discount, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setBorder(PdfPCell.RIGHT);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setPaddingRight(tpPadRight);
				subTable.addCell(cell);

				//Blank Column for Amount Section at sub table
                cell = new PdfPCell(new Phrase("",font));
                cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Service Tax Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Service Tax (5%)", font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
                cell.setBorderWidth(0);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Service Tax Content at sub table
				phrase = new Phrase();
				chunk = new Chunk(ServiceTax, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setBorder(PdfPCell.RIGHT);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setPaddingRight(tpPadRight);
				subTable.addCell(cell);

				//Blank Column for Amount Section at sub table
                cell = new PdfPCell(new Phrase("",font));
                cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Current Charges Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Current Charges\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Caj Semasa", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(3);
                cell.setBorder(PdfPCell.RIGHT + PdfPCell.BOTTOM);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				subTable.addCell(cell);

				//Current Charges Amount at sub table
				phrase = new Phrase();
				chunk = new Chunk(TotalCurrentCharges, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setPaddingRight(tpPadRight);
                cell.setBorder(PdfPCell.BOTTOM);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				subTable.addCell(cell);

				//Total Amount Due Title at sub table
				phrase = new Phrase();
				chunk = new Chunk("Total Amount Due\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Jumlah Perlu Dibayar", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(3);
                cell.setBorder(PdfPCell.RIGHT + PdfPCell.BOTTOM);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				subTable.addCell(cell);

				//Total Amount Due Amount at sub table
				phrase = new Phrase();
				chunk = new Chunk(TotalAmountDue, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setPaddingRight(tpPadRight);
                cell.setBorder(PdfPCell.BOTTOM);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				subTable.addCell(cell);

				//add blank row at sub table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorder(PdfPCell.BOTTOM);
				cell.setColspan(4);
				subTable.addCell(cell);

				//add big blank row at sub table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(4);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//Bill message
				phrase = new Phrase();
				chunk = new Chunk("Bill message / ", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Maklumat Bil:", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Bill message row 1
				phrase = new Phrase();
				chunk = new Chunk(formatStr(MessageLine1), font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setPaddingLeft(tpPadLeft);
				cell.setPaddingRight(tpPadRight);
				cell.setBorder(PdfPCell.TOP + PdfPCell.LEFT + PdfPCell.RIGHT);
				subTable.addCell(cell);

				//Bill message row 2
				phrase = new Phrase();
				chunk = new Chunk(MessageLine2, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setPaddingLeft(tpPadLeft);
				cell.setPaddingRight(tpPadRight);
				cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				subTable.addCell(cell);

				//Bill message row 4
				phrase = new Phrase();
				chunk = new Chunk(MessageLine4, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setPaddingLeft(tpPadLeft);
				cell.setPaddingRight(tpPadRight);
				cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				subTable.addCell(cell);

				//Bill message row 5
				phrase = new Phrase();
				chunk = new Chunk(MessageLine5, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setPaddingLeft(tpPadLeft);
				cell.setPaddingRight(tpPadRight);
				cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				subTable.addCell(cell);

				//Bill message row 6
				phrase = new Phrase();
				chunk = new Chunk(MessageLine6, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setPaddingLeft(tpPadLeft);
				cell.setPaddingRight(tpPadRight);
				cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				subTable.addCell(cell);

				//Bill message row 8
				phrase = new Phrase();
				chunk = new Chunk(MessageLine8 + "\n\n", font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setPaddingLeft(tpPadLeft);
				cell.setPaddingRight(tpPadRight);
				cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				subTable.addCell(cell);				;

				//Bill message row 10
				phrase = new Phrase();
				chunk = new Chunk(formatStr(MessageLine10), fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setPaddingLeft(tpPadLeft);
				cell.setPaddingRight(tpPadRight);
				cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				subTable.addCell(cell);

				//Bill message row 12
				phrase = new Phrase();
				chunk = new Chunk(MessageLine12, fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setPaddingLeft(tpPadLeft);
				cell.setPaddingRight(tpPadRight);
				cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				subTable.addCell(cell);

				//Bill message row 13
				phrase = new Phrase();
				chunk = new Chunk(MessageLine13, fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setPaddingLeft(tpPadLeft);
				cell.setPaddingRight(tpPadRight);
				cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				subTable.addCell(cell);

				//Bill message row 14
				phrase = new Phrase();
				chunk = new Chunk(MessageLine14, fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setPaddingLeft(tpPadLeft);
				cell.setPaddingRight(tpPadRight);
				cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				subTable.addCell(cell);

				//Bill message row 16
				phrase = new Phrase();
				chunk = new Chunk(MessageLine16, fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setPaddingLeft(tpPadLeft);
				cell.setPaddingRight(tpPadRight);
				cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				subTable.addCell(cell);

				//Bill message row 17
				phrase = new Phrase();
				chunk = new Chunk(MessageLine17, fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setPaddingLeft(tpPadLeft);
				cell.setPaddingRight(tpPadRight);
				cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				subTable.addCell(cell);

				//Bill message row 18
				phrase = new Phrase();
				chunk = new Chunk(MessageLine18, fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setPaddingLeft(tpPadLeft);
				cell.setPaddingRight(tpPadRight);
				cell.setPaddingBottom(tpPadBottom);
				cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT + PdfPCell.BOTTOM);
				subTable.addCell(cell);

				//Add subTable
				cell = new PdfPCell(subTable);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorder(PdfPCell.RIGHT + PdfPCell.BOTTOM);
				cell.setPaddingRight(tpPadRight);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				table.addCell(cell);


				//Reuse sub Table inside main table second column
                float[] subTableColsWidth2 = {1f, 1f};
                subTable = new PdfPTable(subTableColsWidth2);

				//Account Number Title
				phrase = new Phrase();
				chunk = new Chunk("Account No.\n ", font);
				phrase.add(chunk);
				chunk = new Chunk("No.Akaun", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Account Number content
				phrase = new Phrase();
				chunk = new Chunk(": " + AccNo + " (new) / " + OldAccountNumber, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Reference No. Title
				phrase = new Phrase();
				chunk = new Chunk("Reference No.\n ", font);
				phrase.add(chunk);
				chunk = new Chunk("No.Rujukan", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Reference No. content
				phrase = new Phrase();
				chunk = new Chunk(": " + RefNo, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Statement Date Title
				phrase = new Phrase();
				chunk = new Chunk("Statement Date\n ", font);
				phrase.add(chunk);
				chunk = new Chunk("Tarikh Penyata", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Statement Date content
				phrase = new Phrase();
				chunk = new Chunk(": " + StmtDt, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Billing Period Title
				phrase = new Phrase();
				chunk = new Chunk("Billing Period\n ", font);
				phrase.add(chunk);
				chunk = new Chunk("Tempoh Bil", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Billing Period content
				phrase = new Phrase();
				chunk = new Chunk(": " + BillPeriod, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Deposit Paid Title
				phrase = new Phrase();
				chunk = new Chunk("Deposit Paid.\n ", font);
				phrase.add(chunk);
				chunk = new Chunk("Cagaran", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Deposit Paid content
				phrase = new Phrase();
				chunk = new Chunk(": " + DepositPaid, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Credit Limit Title
				phrase = new Phrase();
				chunk = new Chunk("Credit Limit\n ", font);
				phrase.add(chunk);
				chunk = new Chunk("Had Kredit", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Credit Limit content
				phrase = new Phrase();
				chunk = new Chunk(": " + CreditLimit, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Add blank row
				cell = new PdfPCell(new Phrase("",fontBold));
				cell.setColspan(2);
				cell.setBorder(PdfPCell.BOTTOM);
				subTable.addCell(cell);

				//Current Promotion title
				phrase = new Phrase();
				chunk = new Chunk("Current Promotion / ", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Promosi Terkini:", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(2);
				cell.setBorderWidth(0);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//add big blank row at sub table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(2);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//Current Promotion repeat section
				if(cfiCurrentPromotionSection!=null){
					StatementSection PromotionRepeatSection = null;
           			long DetailLines = cfiCurrentPromotionSection.getSectionCount("CurrentPromotionRepeatSection");

            		for (int i = 0; i < DetailLines; i++) {
            		    // Get the row section
            		    PromotionRepeatSection = cfiCurrentPromotionSection.getRepeatSection("CurrentPromotionRepeatSection", i);
  						//Column 3 : Name
	        	        cell = new PdfPCell(new Phrase(PromotionRepeatSection.getField("PromotionLine").asString(), font));
            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
            	    	cell.setPaddingLeft(tpPadLeft);
            	    	cell.setColspan(2);
            	    	cell.setBorderWidth(0);
            	    	subTable.addCell(cell);
					}//end For
				}
				//Add subTable
				cell = new PdfPCell(subTable);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorder(PdfPCell.BOTTOM);
				table.addCell(cell);

				//Footer
				//Message
				phrase = new Phrase();
				chunk = new Chunk("", font);
				phrase.add(chunk);
				chunk = new Chunk("", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingTop(tpPadTop);
				table.addCell(cell);

				//Payment Slip title
				phrase = new Phrase();
				chunk = new Chunk("PAYMENT SLIP\n", bigFontBold);
				phrase.add(chunk);
				chunk = new Chunk("SLIP BAYARAN", bigFontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setBorderWidth(0);
				cell.setPaddingRight(tpPadRight);
				table.addCell(cell);

				//Create Table 2 inside main table to hold 2 sub table
                float[] TableColsWidth2 = {6f, 4f};
                PdfPTable table2 = new PdfPTable(TableColsWidth2);

				//Reuse sub Table inside main table fifth column
                float[] subTableColsWidth3 = {1f, 1f};
                subTable = new PdfPTable(subTableColsWidth3);

                //Account Name title
				phrase = new Phrase();
				chunk = new Chunk("Account Name / ", font);
				phrase.add(chunk);
				chunk = new Chunk("Nama Akaun", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Account Name content
				phrase = new Phrase();
				chunk = new Chunk(": " + AccName, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

                //Account no title
				phrase = new Phrase();
				chunk = new Chunk("Account No. / ", font);
				phrase.add(chunk);
				chunk = new Chunk("No. Akaun", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Account no content
				phrase = new Phrase();
				chunk = new Chunk(": " + AccNo + " (new) / " + OldAccountNumber, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

                //phone no title
				phrase = new Phrase();
				chunk = new Chunk("Phone Number / ", font);
				phrase.add(chunk);
				chunk = new Chunk("No.Telefon", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//phone no content
				phrase = new Phrase();
				chunk = new Chunk(": " + PhoneNo, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

                //reference number title
				phrase = new Phrase();
				chunk = new Chunk("Reference Number / ", font);
				phrase.add(chunk);
				chunk = new Chunk("No. Rujukan", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//reference number content
				phrase = new Phrase();
				chunk = new Chunk(": " + RefNo, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//add big blank row at main table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(2);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				table.addCell(cell);

				//add big blank row at main table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(2);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				table.addCell(cell);

				//Add subTable
				cell = new PdfPCell(subTable);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				table2.addCell(cell);

				//Reuse sub Table inside main table sixth column
                float[] subTableColsWidth4 = {2f, 3f};
                subTable = new PdfPTable(subTableColsWidth4);

				//sub table Total Amount Due header
				phrase = new Phrase();
				chunk = new Chunk("Total Amount Due\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Jumlah Perlu Dibayar ", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setGrayFill(0.8f);
				subTable.addCell(cell);

				//sub table header
				phrase = new Phrase();
				chunk = new Chunk("Current Charges Due Date\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Tarikh Akhir Bayaran Due Date ", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setGrayFill(0.8f);
				subTable.addCell(cell);

				//sub table Total Amount Due value
				phrase = new Phrase();
				chunk = new Chunk(TotalAmountDue, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//sub table Current charges due date value
				phrase = new Phrase();
				chunk = new Chunk(CurrentChargesDueDate, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//Add subTable
				cell = new PdfPCell(subTable);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingTop(12);
				table2.addCell(cell);

				//Add Table 2
				cell = new PdfPCell(table2);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setColspan(2);
				table.addCell(cell);

				//add big blank row at main table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(2);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				table.addCell(cell);

				//Account Name and Address
				phrase = new Phrase();
				chunk = new Chunk(AccName + "\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk(Address1 + "\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk(Address2 + "\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk(Address3 + "\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk(Address4 + "\n", fontBold);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(2);
				cell.setBorderWidth(0);
				cell.setPaddingLeft(50);
				table.addCell(cell);

				//blank column
                cell = new PdfPCell(new Phrase("", fontBold));
                cell.setBorderWidth(0);
				table.addCell(cell);

				//statement date
				phrase = new Phrase();
				chunk = new Chunk(StmtDt, fontBold);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setPaddingLeft(tpPadLeft);
				cell.setBorderWidth(0);
				table.addCell(cell);

		   	document.add(table);

			//Get Account Summary Section from root section
		   	final StatementSection cfiAccountSummarySection = cfiRootSection.getSection("AccountSummarySection");

		   	if(cfiAccountSummarySection!=null){
		   		document.newPage();

		   		addAccountSummarySec(writer, document, cfiAccountSummarySection, cfiRootSection);
		   	}

			// add the Details of Charges Section
		   	//Get Details Of Charges Section from root section
		   	final StatementSection cfiDetailsOfChargesSection = cfiRootSection.getSection("DetailsOfChargesSection");

		   	if(cfiDetailsOfChargesSection!=null){

		   		document.newPage();

		   		addDetailsOfChargesSec(writer, document, cfiDetailsOfChargesSection, cfiRootSection);
		   	}

			document.close();
			writer.flush();
            writer.close();

            //PersistServer.commitTransaction();

        } catch (Exception ex) {
            System.err.println("-- EXCEPTION: " + ex.getClass() + " "
                    + ex.getMessage());
            ex.printStackTrace();
        } catch (Throwable t) {
            System.err.println("-- EXCEPTION: " + t.getClass() + " " + t.getMessage());
            t.printStackTrace();
        }finally {
			//PersistServer.deactivate();
		}
    }

    /**
     * add the Account Summary to the table
     *
     * @param writer
     * @param document
     */
        public void addAccountSummarySec(PdfWriter writer, Document document, StatementSection cfiAccountSummarySection, StatementSection cfiRootSection) {

            // padding size for the cell
			int tpPadBottom = 5;
			int tpPadTop = 5;
			int tpPadRight = 5;
			int tpPadLeft = 5;

            try {

                // font used in this section
            	Font font = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL,new Color(0, 0, 0));
				Font fontItalic = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.ITALIC,new Color(0, 0, 0));
				Font fontBold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD,new Color(0, 0, 0));
				Font fontSpace = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL,new Color(0, 0, 0));
				Font bigFontItalic = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC,new Color(0, 0, 0));
				Font bigFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD,new Color(0, 0, 0));

                // transaction detail table column widths
                float headerwidths[] = { 22.0F, 8.0F, 6.0F, 6.0F, 6.0F }; // percentage
                PdfPTable transTable = new PdfPTable(headerwidths.length);
                transTable.setWidths(headerwidths);
                transTable.setWidthPercentage(100); // percentage

                //Get data field from root section
    			final String AccNo = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("AccountNumber"));
    			final String StmtDt = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("StatementDate"));
    			final String AccName = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("AccountName"));
    		  	final String TotalAmountDue = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("TotalAmountDue"));

    		    //Get Others section
    		   	final StatementSection cfiItemsWithRebateSection = cfiAccountSummarySection.getSection("ItemsWithRebateSection");
    			final StatementSection cfiItemsWithoutRebateSection = cfiAccountSummarySection.getSection("ItemsWithoutRebateSection");

    		    //Get Items With Rebate section
    		   	final StatementSection cfiTotalLineChargesSection = cfiItemsWithRebateSection.getSection("TotalLineChargesSection");
    			final StatementSection cfiDiscountsAndRebateSection = cfiItemsWithRebateSection.getSection("DiscountAndRebatesSection");
    			final StatementSection cfiOtherChargesAndCreditSection = cfiItemsWithRebateSection.getSection("OtherChargesAndCreditSection");
    			final StatementSection cfiTotalCurrentChargesSection= cfiItemsWithRebateSection.getSection("TotalCurrentChargesSection");
    			final StatementSection cfiServiceTaxSection = cfiItemsWithRebateSection.getSection("ServiceTaxSection");
    			final StatementSection cfiAdvantageSavingsSection = cfiItemsWithRebateSection.getSection("AdvantageSavingsSection");
    			final StatementSection cfiMonthlyChargesSection = cfiItemsWithRebateSection.getSection("MonthlyChargesSection");
    			final StatementSection cfiValueAddedServciesSection = cfiItemsWithRebateSection.getSection("ValueAddedServciesSection");
    			final StatementSection cfiUsageChargesSection = cfiItemsWithRebateSection.getSection("UsageChargesSection");


                //Declaration
				Chunk chunk;
				Phrase phrase;
                PdfPCell cell = null;
                Image img = null;
                Paragraph newParagraph = null;

                //Title
				phrase = new Phrase();
				chunk = new Chunk("ACCOUNT SUMMARY\n", bigFontBold);
				phrase.add(chunk);
				chunk = new Chunk("RINGKASAN AKAUN", bigFontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
				cell.setColspan(5);
				cell.setBorderWidth(0);
				transTable.addCell(cell);

				//Add blank row
				cell = new PdfPCell(new Phrase("",fontBold));
				cell.setColspan(5);
				cell.setBorderWidth(0);
				transTable.addCell(cell);

				//Statement Date
				phrase = new Phrase();
				chunk = new Chunk("Statement Date / ", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Tarikh Penyata   ", fontItalic);
				phrase.add(chunk);
				chunk = new Chunk(":  " + StmtDt, fontBold);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(5);
				cell.setBorderWidth(0);
				transTable.addCell(cell);

				//Add blank row
				cell = new PdfPCell(new Phrase("",fontBold));
				cell.setColspan(5);
				cell.setBorderWidth(0);
				transTable.addCell(cell);

				//Add blank row
				cell = new PdfPCell(new Phrase("",fontBold));
				cell.setColspan(5);
				cell.setBorderWidth(0);
				transTable.addCell(cell);

				//Add blank row
				cell = new PdfPCell(new Phrase("",fontBold));
				cell.setColspan(5);
				cell.setBorderWidth(0);
				transTable.addCell(cell);

				//Account Name
				phrase = new Phrase();
				chunk = new Chunk("Account Name / ", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Nama Akaun       ", fontItalic);
				phrase.add(chunk);
				chunk = new Chunk(":  " + AccName, fontBold);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(5);
				cell.setBorderWidth(0);
				transTable.addCell(cell);

				// Add 5 blank lines
				for (int i = 0; i < 10; i++) {
					cell = new PdfPCell(new Phrase("",fontBold));
					cell.setColspan(5);
					cell.setBorderWidth(0);
					transTable.addCell(cell);
				}

				// SET THE HEADER ROWS
				//transTable.setHeaderRows(15);
//				transTable.setHeadersInEvent(true);

				//Items Without Rebate section
				if(cfiItemsWithoutRebateSection!=null){

					//Get Items Without Rebate section
	    		   	final StatementSection cfiPaymentsSection = cfiItemsWithoutRebateSection.getSection("PaymentsSection");
	    			final StatementSection cfiAdjustmentsSection = cfiItemsWithoutRebateSection.getSection("AdjustmentsSection");

					//Header 1
					//Column 1 Row 1 Header 1 - Item
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Item", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
		            cell.setBorder(PdfPCell.LEFT + PdfPCell.TOP);
		            cell.setPaddingLeft(tpPadLeft);
		            cell.setPaddingTop(tpPadTop);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 2 Row 1 Header 1 - Date/Period
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Date/Period", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		            cell.setBorder(PdfPCell.TOP);
		            cell.setPaddingTop(tpPadTop);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 3 Row 1 Header 1 - Rebate (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase(" ", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		            cell.setBorder(PdfPCell.TOP);
		            cell.setPaddingTop(tpPadTop);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 4 Row 1 Header 1 - Amount (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Amount (RM)", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		            cell.setBorder(PdfPCell.TOP);
		            cell.setPaddingTop(tpPadTop);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 5 Row 1 Header 1 - Total (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Total (RM)", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		            cell.setBorder(PdfPCell.TOP + PdfPCell.RIGHT);
		            cell.setPaddingTop(tpPadTop);
		            cell.setPaddingRight(tpPadRight);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Header 2
					//Column 1 Row 1 Header 2 - Item
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Item", fontItalic));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
		            cell.setBorder(PdfPCell.LEFT + PdfPCell.BOTTOM);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setPaddingLeft(tpPadLeft);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 2 Row 1 Header 2 - Tarikh/Tempoh
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Tarikh/Tempoh", fontItalic));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		            cell.setBorder(PdfPCell.BOTTOM);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 3 Row 1 Header 2 - Rebat (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase(" ", fontItalic));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		            cell.setBorder(PdfPCell.BOTTOM);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 4 Row 1 Header 2 - Amaun (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Amaun (RM))", fontItalic));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		            cell.setBorder(PdfPCell.BOTTOM);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 5 Row 1 Header 2 - Jumlah (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Jumlah (RM)", fontItalic));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		            cell.setBorder(PdfPCell.BOTTOM + PdfPCell.RIGHT);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setPaddingRight(tpPadRight);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Payments repeat section
					if(cfiPaymentsSection!=null){

						//Payments Header
						newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("Payment", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setBorder(PdfPCell.BOTTOM);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setColspan(5);
			            transTable.addCell(cell);

			            //Payments Repeat Section Part
						StatementSection PaymentsRepeatSection = null;
	           			long DetailLines = cfiPaymentsSection.getSectionCount("RepeatSection");

	            		for (int i = 0; i < DetailLines; i++) {
	            		    // Get the row section
	            			PaymentsRepeatSection = cfiPaymentsSection.getRepeatSection("RepeatSection", i);

	            			//Column 1 : Item
		        	        cell = new PdfPCell(new Phrase(PaymentsRepeatSection.getField("Item").asString(), font));
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	            	    	cell.setPaddingLeft(tpPadLeft);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);

	            	    	//Column 2 : Date
	            	    	if(PaymentsRepeatSection.getField("Date")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(PaymentsRepeatSection.getField("Date").asString(), font));
	            	    	}
	            	    	else
	            	    	{
	            	    		cell = new PdfPCell(new Phrase("", font));
	            	    	}
 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
 	            	    	cell.setBorderWidth(0);
 	            	    	transTable.addCell(cell);

 	            	    	//Column 3 : Rebate
	            	    	cell = new PdfPCell(new Phrase("", font));
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setBorderWidth(0);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	transTable.addCell(cell);

	            	    	//Column 4 : Amount
 	            	    	if(PaymentsRepeatSection.getField("Amount")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(PaymentsRepeatSection.getField("Amount").asString(), font));
	            	    	}
	            	    	else
	            	    	{
	            	    		cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setBorderWidth(0);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	transTable.addCell(cell);

	            	    	//Column 5 : Total
	            	    	if(PaymentsRepeatSection.getField("Total")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(PaymentsRepeatSection.getField("Total").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);
						}//end For

	            		//Add a Blank Line
	            		cell = new PdfPCell(new Phrase("",fontBold));
    					cell.setColspan(5);
    					cell.setBorderWidth(0);
    					transTable.addCell(cell);
					}

					//Adjustments repeat section
					if(cfiAdjustmentsSection!=null){

						//Adjustments Header
						newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("Adjustment", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setBorder(PdfPCell.BOTTOM);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setColspan(5);
			            transTable.addCell(cell);

			            //Adjustments Repeat Section Part
						StatementSection AdjustmentsRepeatSection = null;
	           			long DetailLines = cfiAdjustmentsSection.getSectionCount("RepeatSection");

	            		for (int i = 0; i < DetailLines; i++) {
	            		    // Get the row section
	            			AdjustmentsRepeatSection = cfiAdjustmentsSection.getRepeatSection("RepeatSection", i);

	            			//Column 1 : Item
		        	        cell = new PdfPCell(new Phrase(AdjustmentsRepeatSection.getField("Item").asString(), font));
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	            	    	cell.setPaddingLeft(tpPadLeft);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);

	            	    	//Column 2 : Date
	            	    	if(AdjustmentsRepeatSection.getField("Date")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(AdjustmentsRepeatSection.getField("Date").asString(), font));
	            	    	}
	            	    	else
	            	    	{
	            	    		cell = new PdfPCell(new Phrase("", font));
	            	    	}
 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
 	            	    	cell.setBorderWidth(0);
 	            	    	transTable.addCell(cell);

 	            	    	//Column 3 : Rebate
	            	    	cell = new PdfPCell(new Phrase("", font));
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setBorderWidth(0);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	transTable.addCell(cell);

	            	    	//Column 4 : Amount
 	            	    	if(AdjustmentsRepeatSection.getField("Amount")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(AdjustmentsRepeatSection.getField("Amount").asString(), font));
	            	    	}
	            	    	else
	            	    	{
	            	    		cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setBorderWidth(0);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	transTable.addCell(cell);

	            	    	//Column 5 : Total
	            	    	if(AdjustmentsRepeatSection.getField("Total")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(AdjustmentsRepeatSection.getField("Total").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);
						}//end For

	            		//Add a Blank Line
	            		cell = new PdfPCell(new Phrase("",fontBold));
    					cell.setColspan(5);
    					cell.setBorderWidth(0);
    					transTable.addCell(cell);
					}
				}

				//Items With Rebate section
				if(cfiItemsWithRebateSection!=null){

					//Header 1
					//Column 1 Row 1 Header 1 - Item
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Item", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
		            cell.setBorder(PdfPCell.LEFT + PdfPCell.TOP);
		            cell.setPaddingLeft(tpPadLeft);
		            cell.setPaddingTop(tpPadTop);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 2 Row 1 Header 1 - Date/Period
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Date/Period", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		            cell.setBorder(PdfPCell.TOP);
		            cell.setPaddingTop(tpPadTop);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 3 Row 1 Header 1 - Rebate (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Rebate (RM)", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		            cell.setBorder(PdfPCell.TOP);
		            cell.setPaddingTop(tpPadTop);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 4 Row 1 Header 1 - Amount (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Amount (RM)", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		            cell.setBorder(PdfPCell.TOP);
		            cell.setPaddingTop(tpPadTop);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 5 Row 1 Header 1 - Total (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Total (RM)", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		            cell.setBorder(PdfPCell.TOP + PdfPCell.RIGHT);
		            cell.setPaddingTop(tpPadTop);
		            cell.setPaddingRight(tpPadRight);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Header 2
					//Column 1 Row 1 Header 2 - Item
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Item", fontItalic));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
		            cell.setBorder(PdfPCell.LEFT + PdfPCell.BOTTOM);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setPaddingLeft(tpPadLeft);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 2 Row 1 Header 2 - Tarikh/Tempoh
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Tarikh/Tempoh", fontItalic));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		            cell.setBorder(PdfPCell.BOTTOM);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 3 Row 1 Header 2 - Rebat (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Rebat (RM)", fontItalic));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		            cell.setBorder(PdfPCell.BOTTOM);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 4 Row 1 Header 2 - Amaun (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Amaun (RM))", fontItalic));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		            cell.setBorder(PdfPCell.BOTTOM);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 5 Row 1 Header 2 - Jumlah (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Jumlah (RM)", fontItalic));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		            cell.setBorder(PdfPCell.BOTTOM + PdfPCell.RIGHT);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setPaddingRight(tpPadRight);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            // SET THE HEADER ROWS
					transTable.setHeaderRows(19);

		            //Monthly Charges repeat section
					if(cfiMonthlyChargesSection!=null){

						//Monthly Charges Header
						newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("Monthly Charges", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setBorder(PdfPCell.BOTTOM);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setColspan(5);
			            transTable.addCell(cell);

			            //Monthly Charges Repeat Section Part
						StatementSection MonthlyChargesRepeatSection = null;
	           			long DetailLines = cfiMonthlyChargesSection.getSectionCount("RepeatSection");

	            		for (int i = 0; i < DetailLines; i++) {
	            		    // Get the row section
	            			MonthlyChargesRepeatSection = cfiMonthlyChargesSection.getRepeatSection("RepeatSection", i);

	            			//Column 1 : Item
		        	        cell = new PdfPCell(new Phrase(MonthlyChargesRepeatSection.getField("Item").asString(), font));
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	            	    	cell.setPaddingLeft(tpPadLeft);
	            	    	if(MonthlyChargesRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell.setColspan(2);
	            	    	}
	            	    	else
	            	    	{
	            	    		cell.setColspan(3);
	            	    	}
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);

	            	    	//Column 2 : Rebate
	            	    	if(MonthlyChargesRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(MonthlyChargesRepeatSection.getField("Rebate").asString(), font));
	 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	 	            	    	cell.setBorderWidth(0);
	 	            	    	cell.setPaddingRight(tpPadRight);
	 	            	    	transTable.addCell(cell);
	            	    	}

	            	    	//Column 2 : Amount
	            	    	if(MonthlyChargesRepeatSection.getField("Amount")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(MonthlyChargesRepeatSection.getField("Amount").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setBorderWidth(0);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	transTable.addCell(cell);

	            	    	//Column 3 : Total
	            	    	if(MonthlyChargesRepeatSection.getField("Total")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(MonthlyChargesRepeatSection.getField("Total").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);
						}//end For

	            		//Add a Blank Line
	            		cell = new PdfPCell(new Phrase("",fontBold));
    					cell.setColspan(5);
    					cell.setBorderWidth(0);
    					transTable.addCell(cell);
					}

					//Value Added Servcies repeat section
					if(cfiValueAddedServciesSection!=null){

						//Value Added Servcies Header
						newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("Value Added Servcies", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setBorder(PdfPCell.BOTTOM);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setColspan(5);
			            transTable.addCell(cell);

			            //Value Added Servcies Repeat Section Part
						StatementSection ValueAddedServciesRepeatSection = null;
	           			long DetailLines = cfiValueAddedServciesSection.getSectionCount("RepeatSection");

	            		for (int i = 0; i < DetailLines; i++) {
	            		    // Get the row section
	            			ValueAddedServciesRepeatSection = cfiValueAddedServciesSection.getRepeatSection("RepeatSection", i);

	            			//Column 1 : Item
		        	        cell = new PdfPCell(new Phrase(ValueAddedServciesRepeatSection.getField("Item").asString(), font));
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	            	    	cell.setPaddingLeft(tpPadLeft);
	            	    	if(ValueAddedServciesRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell.setColspan(2);
	            	    	}
	            	    	else
	            	    	{
	            	    		cell.setColspan(3);
	            	    	}
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);

	            	    	//Column 2 : Rebate
	            	    	if(ValueAddedServciesRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(ValueAddedServciesRepeatSection.getField("Rebate").asString(), font));
	 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	 	            	    	cell.setBorderWidth(0);
	 	            	    	cell.setPaddingRight(tpPadRight);
	 	            	    	transTable.addCell(cell);
	            	    	}

	            	    	//Column 2 : Amount
	            	    	if(ValueAddedServciesRepeatSection.getField("Amount")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(ValueAddedServciesRepeatSection.getField("Amount").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setBorderWidth(0);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	transTable.addCell(cell);

	            	    	//Column 3 : Total
	            	    	if(ValueAddedServciesRepeatSection.getField("Total")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(ValueAddedServciesRepeatSection.getField("Total").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);
						}//end For

	            		//Add a Blank Line
	            		cell = new PdfPCell(new Phrase("",fontBold));
    					cell.setColspan(5);
    					cell.setBorderWidth(0);
    					transTable.addCell(cell);
					}

					//Usage Charges repeat section
					if(cfiUsageChargesSection!=null){

						//Usage Charges Header
						newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("Usage Charges", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setBorder(PdfPCell.BOTTOM);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setColspan(5);
			            transTable.addCell(cell);

			            //Usage Charges Section Part
						StatementSection UsageChargesRepeatSection = null;
	           			long DetailLines = cfiUsageChargesSection.getSectionCount("RepeatSection");

	            		for (int i = 0; i < DetailLines; i++) {
	            		    // Get the row section
	            			UsageChargesRepeatSection = cfiUsageChargesSection.getRepeatSection("RepeatSection", i);

	            			//Column 1 : Item
		        	        cell = new PdfPCell(new Phrase(UsageChargesRepeatSection.getField("Item").asString(), font));
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	            	    	cell.setPaddingLeft(tpPadLeft);
	            	    	if(UsageChargesRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell.setColspan(2);
	            	    	}
	            	    	else
	            	    	{
	            	    		cell.setColspan(3);
	            	    	}
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);

	            	    	//Column 2 : Rebate
	            	    	if(UsageChargesRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(UsageChargesRepeatSection.getField("Rebate").asString(), font));
	 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	 	            	    	cell.setBorderWidth(0);
	 	            	    	cell.setPaddingRight(tpPadRight);
	 	            	    	transTable.addCell(cell);
	            	    	}

	            	    	//Column 2 : Amount
	            	    	if(UsageChargesRepeatSection.getField("Amount")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(UsageChargesRepeatSection.getField("Amount").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setBorderWidth(0);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	transTable.addCell(cell);

	            	    	//Column 3 : Total
	            	    	if(UsageChargesRepeatSection.getField("Total")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(UsageChargesRepeatSection.getField("Total").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);
						}//end For

	            		//Add a Blank Line
	            		cell = new PdfPCell(new Phrase("",fontBold));
    					cell.setColspan(5);
    					cell.setBorderWidth(0);
    					transTable.addCell(cell);
					}

					//Discount & Rebates repeat section
					if(cfiDiscountsAndRebateSection!=null){

						//Discount & Rebates Header
						newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("Discount & Rebates", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setBorder(PdfPCell.BOTTOM);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setColspan(5);
			            transTable.addCell(cell);

			            //Discount & Rebates Section Part
						StatementSection DiscountsAndRebateRepeatSection = null;
	           			long DetailLines = cfiDiscountsAndRebateSection.getSectionCount("RepeatSection");

	            		for (int i = 0; i < DetailLines; i++) {
	            		    // Get the row section
	            			DiscountsAndRebateRepeatSection = cfiDiscountsAndRebateSection.getRepeatSection("RepeatSection", i);

	            			//Column 1 : Item
		        	        cell = new PdfPCell(new Phrase(DiscountsAndRebateRepeatSection.getField("Item").asString(), font));
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	            	    	cell.setPaddingLeft(tpPadLeft);
	            	    	if(DiscountsAndRebateRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell.setColspan(2);
	            	    	}
	            	    	else
	            	    	{
	            	    		cell.setColspan(3);
	            	    	}
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);

	            	    	//Column 2 : Rebate
	            	    	if(DiscountsAndRebateRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(DiscountsAndRebateRepeatSection.getField("Rebate").asString(), font));
	 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	 	            	    	cell.setBorderWidth(0);
	 	            	    	cell.setPaddingRight(tpPadRight);
	 	            	    	transTable.addCell(cell);
	            	    	}

	            	    	//Column 2 : Amount
	            	    	if(DiscountsAndRebateRepeatSection.getField("Amount")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(DiscountsAndRebateRepeatSection.getField("Amount").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setBorderWidth(0);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	transTable.addCell(cell);

	            	    	//Column 3 : Total
	            	    	if(DiscountsAndRebateRepeatSection.getField("Total")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(DiscountsAndRebateRepeatSection.getField("Total").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);
						}//end For

	            		//Add a Blank Line
	            		cell = new PdfPCell(new Phrase("",fontBold));
    					cell.setColspan(5);
    					cell.setBorderWidth(0);
    					transTable.addCell(cell);
					}

					//Service Tax repeat section
					if(cfiServiceTaxSection!=null){

						//Service Tax Header
						newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("Service Tax (5%)", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setBorder(PdfPCell.BOTTOM);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setColspan(5);
			            transTable.addCell(cell);

			            //Service Tax Section Part
						StatementSection ServiceTaxRepeatSection = null;
	           			long DetailLines = cfiServiceTaxSection.getSectionCount("RepeatSection");

	            		for (int i = 0; i < DetailLines; i++) {
	            		    // Get the row section
	            			ServiceTaxRepeatSection = cfiServiceTaxSection.getRepeatSection("RepeatSection", i);

	            			//Column 1 : Item
		        	        cell = new PdfPCell(new Phrase(ServiceTaxRepeatSection.getField("Item").asString(), font));
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	            	    	cell.setPaddingLeft(tpPadLeft);
	            	    	if(ServiceTaxRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell.setColspan(2);
	            	    	}
	            	    	else
	            	    	{
	            	    		cell.setColspan(3);
	            	    	}
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);

	            	    	//Column 2 : Rebate
	            	    	if(ServiceTaxRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(ServiceTaxRepeatSection.getField("Rebate").asString(), font));
	 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	 	            	    	cell.setBorderWidth(0);
	 	            	    	cell.setPaddingRight(tpPadRight);
	 	            	    	transTable.addCell(cell);
	            	    	}

	            	    	//Column 2 : Amount
	            	    	if(ServiceTaxRepeatSection.getField("Amount")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(ServiceTaxRepeatSection.getField("Amount").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setBorderWidth(0);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	transTable.addCell(cell);

	            	    	//Column 3 : Total
	            	    	if(ServiceTaxRepeatSection.getField("Total")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(ServiceTaxRepeatSection.getField("Total").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);
						}//end For

	            		//Add a Blank Line
	            		cell = new PdfPCell(new Phrase("",fontBold));
    					cell.setColspan(5);
    					cell.setBorderWidth(0);
    					transTable.addCell(cell);
					}

					//Extra Account Summary Section Start///////////////////////

					//Other Charges And Credit repeat section
					if(cfiOtherChargesAndCreditSection!=null){

						//Other Charges And Credit Header
						newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("Other Charges & Credit", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setBorder(PdfPCell.BOTTOM);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setColspan(5);
			            transTable.addCell(cell);

			            //Other Charges And Credit Section Part
						StatementSection OtherChargesAndCreditRepeatSection = null;
	           			long DetailLines = cfiOtherChargesAndCreditSection.getSectionCount("RepeatSection");

	            		for (int i = 0; i < DetailLines; i++) {
	            		    // Get the row section
	            			OtherChargesAndCreditRepeatSection = cfiOtherChargesAndCreditSection.getRepeatSection("RepeatSection", i);

	            			//Column 1 : Item
		        	        cell = new PdfPCell(new Phrase(OtherChargesAndCreditRepeatSection.getField("Item").asString(), font));
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	            	    	cell.setPaddingLeft(tpPadLeft);
	            	    	if(OtherChargesAndCreditRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell.setColspan(2);
	            	    	}
	            	    	else
	            	    	{
	            	    		cell.setColspan(3);
	            	    	}
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);

	            	    	//Column 2 : Rebate
	            	    	if(OtherChargesAndCreditRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(OtherChargesAndCreditRepeatSection.getField("Rebate").asString(), font));
	 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	 	            	    	cell.setBorderWidth(0);
	 	            	    	cell.setPaddingRight(tpPadRight);
	 	            	    	transTable.addCell(cell);
	            	    	}

	            	    	//Column 2 : Amount
	            	    	if(OtherChargesAndCreditRepeatSection.getField("Amount")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(OtherChargesAndCreditRepeatSection.getField("Amount").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setBorderWidth(0);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	transTable.addCell(cell);

	            	    	//Column 3 : Total
	            	    	if(OtherChargesAndCreditRepeatSection.getField("Total")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(OtherChargesAndCreditRepeatSection.getField("Total").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);
						}//end For

	            		//Add a Blank Line
	            		cell = new PdfPCell(new Phrase("",fontBold));
    					cell.setColspan(5);
    					cell.setBorderWidth(0);
    					transTable.addCell(cell);
					}

					//Advantage Savings repeat section
					if(cfiAdvantageSavingsSection!=null){

						//Advantage Savings Header
						newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("Advantage Savings", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setBorder(PdfPCell.BOTTOM);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setColspan(5);
			            transTable.addCell(cell);

			            //Advantage Savings Section Part
						StatementSection AdvantageSavingsRepeatSection = null;
	           			long DetailLines = cfiAdvantageSavingsSection.getSectionCount("RepeatSection");

	            		for (int i = 0; i < DetailLines; i++) {
	            		    // Get the row section
	            			AdvantageSavingsRepeatSection = cfiAdvantageSavingsSection.getRepeatSection("RepeatSection", i);

	            			//Column 1 : Item
		        	        cell = new PdfPCell(new Phrase(AdvantageSavingsRepeatSection.getField("Item").asString(), font));
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	            	    	cell.setPaddingLeft(tpPadLeft);
	            	    	if(AdvantageSavingsRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell.setColspan(2);
	            	    	}
	            	    	else
	            	    	{
	            	    		cell.setColspan(3);
	            	    	}
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);

	            	    	//Column 2 : Rebate
	            	    	if(AdvantageSavingsRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(AdvantageSavingsRepeatSection.getField("Rebate").asString(), font));
	 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	 	            	    	cell.setBorderWidth(0);
	 	            	    	cell.setPaddingRight(tpPadRight);
	 	            	    	transTable.addCell(cell);
	            	    	}

	            	    	//Column 2 : Amount
	            	    	if(AdvantageSavingsRepeatSection.getField("Amount")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(AdvantageSavingsRepeatSection.getField("Amount").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setBorderWidth(0);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	transTable.addCell(cell);

	            	    	//Column 3 : Total
	            	    	if(AdvantageSavingsRepeatSection.getField("Total")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(AdvantageSavingsRepeatSection.getField("Total").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);
						}//end For

	            		//Add a Blank Line
	            		cell = new PdfPCell(new Phrase("",fontBold));
    					cell.setColspan(5);
    					cell.setBorderWidth(0);
    					transTable.addCell(cell);
					}

					//Extra Account Summary Section End/////////////////////////

					//Add a Blank Line and Line
            		cell = new PdfPCell(new Phrase("",fontBold));
					cell.setColspan(5);
					cell.setPaddingLeft(tpPadLeft);
					cell.setPaddingRight(tpPadRight);
					cell.setBorder(PdfPCell.BOTTOM);
					transTable.addCell(cell);

					//Total Current Charges section
					if(cfiTotalCurrentChargesSection!=null){

						//Total Current Charges	- Item
						newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("Total Current Charges", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setBorder(0);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setColspan(4);
			            transTable.addCell(cell);

			            //Total Current Charges	- Total
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiTotalCurrentChargesSection.getField("Total").asString(), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setBorder(0);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            transTable.addCell(cell);
					}

					//Total Line Charges section
					if(cfiTotalLineChargesSection!=null){

						//Add a Blank Line
	            		cell = new PdfPCell(new Phrase("",fontBold));
    					cell.setColspan(5);
    					cell.setBorderWidth(0);
    					transTable.addCell(cell);

			            //Total Line Charges Section Part
						StatementSection TotalLineChargesRepeatSection = null;
	           			long DetailLines = cfiTotalLineChargesSection.getSectionCount("RepeatSection");

	            		for (int i = 0; i < DetailLines; i++) {
	            		    // Get the row section
	            			TotalLineChargesRepeatSection = cfiTotalLineChargesSection.getRepeatSection("RepeatSection", i);

	            			//Column 1 : Item
	            			if(TotalLineChargesRepeatSection.getField("Item").asString().trim().startsWith("Service Tax")||
	            			   TotalLineChargesRepeatSection.getField("Item").asString().trim().startsWith("Total"))
	            			{
	            				cell = new PdfPCell(new Phrase(TotalLineChargesRepeatSection.getField("Item").asString(), fontBold));
	            			}
	            			else
	            			{
	            				cell = new PdfPCell(new Phrase(TotalLineChargesRepeatSection.getField("Item").asString(), font));
	            			}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	            	    	cell.setPaddingLeft(tpPadLeft);
	            	    	if(TotalLineChargesRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell.setColspan(2);
	            	    	}
	            	    	else
	            	    	{
	            	    		cell.setColspan(3);
	            	    	}
	            	    	if(i==0)
	            	    	{
	            	    		cell.setPaddingTop(tpPadTop);
	            	    		cell.setBorder(PdfPCell.TOP + PdfPCell.LEFT);
	            	    	}
	            	    	else if(i==DetailLines-1)
	            	    	{
	            	    		cell.setPaddingBottom(tpPadBottom);
	            	    		cell.setBorder(PdfPCell.BOTTOM + PdfPCell.LEFT);
	            	    	}
	            	    	else
	            	    	{
	            	    		cell.setBorder(PdfPCell.LEFT);
	            	    	}
	            	    	transTable.addCell(cell);

	            	    	//Column 2 : Rebate
	            	    	if(TotalLineChargesRepeatSection.getField("Rebate")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(TotalLineChargesRepeatSection.getField("Rebate").asString(), font));
	 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	 	            	    	cell.setPaddingRight(tpPadRight);
	 	            	    	if(i==0)
		            	    	{
		            	    		cell.setPaddingTop(tpPadTop);
		            	    		cell.setBorder(PdfPCell.TOP);
		            	    	}
		            	    	else if(i==DetailLines-1)
		            	    	{
		            	    		cell.setPaddingBottom(tpPadBottom);
		            	    		cell.setBorder(PdfPCell.BOTTOM);
		            	    	}
		            	    	else
		            	    	{
		            	    		cell.setBorder(0);
		            	    	}
	 	            	    	transTable.addCell(cell);
	            	    	}

	            	    	//Column 2 : Amount
	            	    	if(TotalLineChargesRepeatSection.getField("Amount")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(TotalLineChargesRepeatSection.getField("Amount").asString(), font));
	            	    	}
	            	    	else
	            	    	{
	            	    		cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	if(i==0)
	            	    	{
	            	    		cell.setPaddingTop(tpPadTop);
	            	    		cell.setBorder(PdfPCell.TOP);
	            	    	}
	            	    	else if(i==DetailLines-1)
	            	    	{
	            	    		cell.setPaddingBottom(tpPadBottom);
	            	    		cell.setBorder(PdfPCell.BOTTOM);
	            	    	}
	            	    	else
	            	    	{
	            	    		cell.setBorder(0);
	            	    	}
	            	    	transTable.addCell(cell);

	            	    	//Column 3 : Total
	            	    	if(TotalLineChargesRepeatSection.getField("Total")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(TotalLineChargesRepeatSection.getField("Total").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}

	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	if(i==0)
	            	    	{
	            	    		cell.setPaddingTop(tpPadTop);
	            	    		cell.setBorder(PdfPCell.TOP + PdfPCell.RIGHT);
	            	    	}
	            	    	else if(i==DetailLines-1)
	            	    	{
	            	    		cell.setPaddingBottom(tpPadBottom);
	            	    		cell.setBorder(PdfPCell.BOTTOM + PdfPCell.RIGHT);
	            	    	}
	            	    	else
	            	    	{
	            	    		cell.setBorder(PdfPCell.RIGHT);
	            	    	}
	            	    	transTable.addCell(cell);
						}//end For
					}

				}

				// Add 5 blank lines testing
//				for (int i = 0; i < 100; i++) {
//					cell = new PdfPCell(new Phrase("",fontBold));
//					cell.setColspan(5);
//					cell.setBorderWidth(0);
//					transTable.addCell(cell);
//				}

				// add the table to the document
				document.add(transTable);

            } catch (DocumentException de) {
                System.err.println(de.getMessage());
                de.printStackTrace();
            } catch (Exception ex) {
                System.err.println(ex.getMessage());
                ex.printStackTrace();
            }
        }

    /**
     * add the Details of Charges to the table
     *
     * @param writer
     * @param document
     */
        public void addDetailsOfChargesSec(PdfWriter writer, Document document, StatementSection cfiDetailsOfChargesSection, StatementSection cfiRootSection) {

            // padding size for the cell
			int tpPadBottom = 5;
			int tpPadTop = 5;
			int tpPadRight = 5;
			int tpPadLeft = 5;

            try {

                // font used in this section
            	Font font = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL,new Color(0, 0, 0));
				Font fontItalic = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.ITALIC,new Color(0, 0, 0));
				Font fontBold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD,new Color(0, 0, 0));
				Font fontSpace = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL,new Color(0, 0, 0));
				Font bigFontItalic = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC,new Color(0, 0, 0));
				Font bigFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD,new Color(0, 0, 0));

    			//Phone Number section
				if(cfiDetailsOfChargesSection!=null){

		            //Total Line Charges Section Part
					StatementSection PhoneNumberRepeatSection = null;
           			long DetailLines2 = cfiDetailsOfChargesSection.getSectionCount("PhoneNumberSection");

            		for (int k = 0; k < DetailLines2; k++) {

            			// transaction detail table column widths
                        float headerwidths[] = { 22.0F, 8.0F, 6.0F, 6.0F, 6.0F }; // percentage
                        PdfPTable transTable = new PdfPTable(headerwidths.length);
                        transTable.setWidths(headerwidths);
                        transTable.setWidthPercentage(100); // percentage

                        //Get data field from root section
            			final String AccNo = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("AccountNumber"));
            			final String StmtDt = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("StatementDate"));
            			final String AccName = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("AccountName"));
            		  	final String TotalAmountDue = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("TotalAmountDue"));

            		    // Get the row section
            			PhoneNumberRepeatSection = cfiDetailsOfChargesSection.getRepeatSection("PhoneNumberSection", k);

		    		   	StatementSection cfiItemsWithRebateSection = PhoneNumberRepeatSection.getSection("ItemWithRebateSection");

		    		    //Get Items With Rebate section
		    		   	StatementSection cfiTotalLineChargesSection = cfiItemsWithRebateSection.getSection("TotalLineChargesSection");
		    			StatementSection cfiDiscountsAndRebateSection = cfiItemsWithRebateSection.getSection("DiscountAndRebatesSection");
		    			StatementSection cfiOtherChargesAndCreditSection = cfiItemsWithRebateSection.getSection("OtherChargesAndCreditSection");
		    			StatementSection cfiServiceTaxSection = cfiItemsWithRebateSection.getSection("ServiceTaxSection");
		    			StatementSection cfiAdvantageSavingsSection = cfiItemsWithRebateSection.getSection("AdvantageSavingsSection");
		    			StatementSection cfiAccessChargesSection= cfiItemsWithRebateSection.getSection("AccessChargesSection");
		    			StatementSection cfiRegistrationChargesSection= cfiItemsWithRebateSection.getSection("RegistrationChargesSection");
		    			StatementSection cfiMonthlyChargesSection = cfiItemsWithRebateSection.getSection("MonthlyChargesSection");
		    			StatementSection cfiValueAddedServciesSection = cfiItemsWithRebateSection.getSection("ValueAddedServicesSection");
		    			StatementSection cfiUsageChargesSection = cfiItemsWithRebateSection.getSection("UsageChargesSection");

		                //Declaration
						Chunk chunk;
						Phrase phrase;
		                PdfPCell cell = null;
		                Image img = null;
		                Paragraph newParagraph = null;

		                //Title
						phrase = new Phrase();
						chunk = new Chunk("DETAILS OF CHARGES\n", bigFontBold);
						phrase.add(chunk);
						chunk = new Chunk("BUTIR-BUTIR CAJ", bigFontItalic);
						phrase.add(chunk);
		                cell = new PdfPCell(phrase);
						cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
						cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						//Add blank row
						cell = new PdfPCell(new Phrase("",fontBold));
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						//Statement Date
						phrase = new Phrase();
						chunk = new Chunk("Statement Date / ", fontBold);
						phrase.add(chunk);
						chunk = new Chunk("Tarikh Penyata   ", fontItalic);
						phrase.add(chunk);
						chunk = new Chunk(":  " + StmtDt, fontBold);
						phrase.add(chunk);
		                cell = new PdfPCell(phrase);
						cell.setHorizontalAlignment(Element.ALIGN_LEFT);
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						//Add blank row
						cell = new PdfPCell(new Phrase("",fontBold));
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						//Phone Number
						phrase = new Phrase();
						chunk = new Chunk("Phone Number / ", fontBold);
						phrase.add(chunk);
						chunk = new Chunk("No.Telefon          ", fontItalic);
						phrase.add(chunk);
						chunk = new Chunk(": " + PhoneNumberRepeatSection.getField("PhoneNumber").asString().replaceAll(":",""), fontBold);
						phrase.add(chunk);
		                cell = new PdfPCell(phrase);
						cell.setHorizontalAlignment(Element.ALIGN_LEFT);
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						//Add blank row
						cell = new PdfPCell(new Phrase("",fontBold));
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						//Account Name
						phrase = new Phrase();
						chunk = new Chunk("Account Name / ", fontBold);
						phrase.add(chunk);
						chunk = new Chunk("Nama Akaun       ", fontItalic);
						phrase.add(chunk);
						chunk = new Chunk(":  " + AccName, fontBold);
						phrase.add(chunk);
		                cell = new PdfPCell(phrase);
						cell.setHorizontalAlignment(Element.ALIGN_LEFT);
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						// Add 5 blank lines
						for (int j = 0; j < 10; j++) {
							cell = new PdfPCell(new Phrase("",fontBold));
							cell.setColspan(5);
							cell.setBorderWidth(0);
							transTable.addCell(cell);
						}

						// SET THE HEADER ROWS
		//    				transTable.setHeaderRows(12);
		//    				transTable.setHeadersInEvent(true);


						//Items With Rebate section
						if(cfiItemsWithRebateSection!=null){

							//Header 1
							//Column 1 Row 1 Header 1 - Item
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Item", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.TOP);
				            cell.setPaddingLeft(tpPadLeft);
				            cell.setPaddingTop(tpPadTop);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 2 Row 1 Header 1 - Date/Period
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Date/Period", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
				            cell.setBorder(PdfPCell.TOP);
				            cell.setPaddingTop(tpPadTop);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 3 Row 1 Header 1 - Rebate (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Rebate (RM)", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
				            cell.setBorder(PdfPCell.TOP);
				            cell.setPaddingTop(tpPadTop);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 4 Row 1 Header 1 - Amount (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Amount (RM)", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.TOP);
				            cell.setPaddingTop(tpPadTop);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 5 Row 1 Header 1 - Total (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Total (RM)", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.TOP + PdfPCell.RIGHT);
				            cell.setPaddingTop(tpPadTop);
				            cell.setPaddingRight(tpPadRight);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Header 2
							//Column 1 Row 1 Header 2 - Item
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Item", fontItalic));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.BOTTOM);
				            cell.setPaddingBottom(tpPadBottom);
				            cell.setPaddingLeft(tpPadLeft);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 2 Row 1 Header 2 - Tarikh/Tempoh
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Tarikh/Tempoh", fontItalic));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
				            cell.setBorder(PdfPCell.BOTTOM);
				            cell.setPaddingBottom(tpPadBottom);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 3 Row 1 Header 2 - Rebat (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Rebat (RM)", fontItalic));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
				            cell.setBorder(PdfPCell.BOTTOM);
				            cell.setPaddingBottom(tpPadBottom);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 4 Row 1 Header 2 - Amaun (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Amaun (RM))", fontItalic));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.BOTTOM);
				            cell.setPaddingBottom(tpPadBottom);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 5 Row 1 Header 2 - Jumlah (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Jumlah (RM)", fontItalic));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.BOTTOM + PdfPCell.RIGHT);
				            cell.setPaddingBottom(tpPadBottom);
				            cell.setPaddingRight(tpPadRight);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            // SET THE HEADER ROWS
							transTable.setHeaderRows(19);

				            //Monthly Charges repeat section
							if(cfiMonthlyChargesSection!=null){

								//Monthly Charges Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Monthly Charges", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Monthly Charges Repeat Section Part
								StatementSection MonthlyChargesRepeatSection = null;
			           			long DetailLines = cfiMonthlyChargesSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			MonthlyChargesRepeatSection = cfiMonthlyChargesSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
			            			if(MonthlyChargesRepeatSection.getField("Item")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(MonthlyChargesRepeatSection.getField("Item").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(MonthlyChargesRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(MonthlyChargesRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
			            	    	if(MonthlyChargesRepeatSection.getField("Rebate")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(MonthlyChargesRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(MonthlyChargesRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(MonthlyChargesRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(MonthlyChargesRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(MonthlyChargesRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Value Added Servcies repeat section
							if(cfiValueAddedServciesSection!=null){

								//Value Added Servcies Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Value Added Servcies", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Value Added Servcies Repeat Section Part
								StatementSection ValueAddedServciesRepeatSection = null;
			           			long DetailLines = cfiValueAddedServciesSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			ValueAddedServciesRepeatSection = cfiValueAddedServciesSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(ValueAddedServciesRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(ValueAddedServciesRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(ValueAddedServciesRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
		 	            	    	if(ValueAddedServciesRepeatSection.getField("Rebate")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(ValueAddedServciesRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(ValueAddedServciesRepeatSection.getField("Amount")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(ValueAddedServciesRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(ValueAddedServciesRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(ValueAddedServciesRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Usage Charges repeat section
							if(cfiUsageChargesSection!=null){

								//Usage Charges Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Usage Charges", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Usage Charges Section Part
								StatementSection UsageChargesRepeatSection = null;
			           			long DetailLines = cfiUsageChargesSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			UsageChargesRepeatSection = cfiUsageChargesSection.getRepeatSection("RepeatSection", i);

			            			//SubRepeatSection
				           			StatementSection SupUsageChargesRepeatSection = null;
				           			long subDetailLines = UsageChargesRepeatSection.getSectionCount("SubRepeatSection");

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(UsageChargesRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(UsageChargesRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(UsageChargesRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
		 	            	    	if(UsageChargesRepeatSection.getField("Rebate")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(UsageChargesRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(UsageChargesRepeatSection.getField("Amount")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(UsageChargesRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(UsageChargesRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(UsageChargesRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	for (int l = 0; l < subDetailLines; l++) {
				            		    // Get the row section
			            	    		SupUsageChargesRepeatSection = UsageChargesRepeatSection.getRepeatSection("SubRepeatSection", l);

			            	    		//Column 1 : Item
					        	        cell = new PdfPCell(new Phrase(SupUsageChargesRepeatSection.getField("Item").asString(), font));
				            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
				            	    	cell.setPaddingLeft(tpPadLeft+tpPadLeft);
				            	    	cell.setBorderWidth(0);
				            	    	transTable.addCell(cell);

				            	    	//Column 2 : Date/Period
				            	    	cell = new PdfPCell(new Phrase("", font));
			 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
			 	            	    	cell.setBorderWidth(0);
			 	            	    	transTable.addCell(cell);

				            	    	//Column 3 : Rebate
				            	    	cell = new PdfPCell(new Phrase("", font));
			 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			 	            	    	cell.setBorderWidth(0);
			 	            	    	cell.setPaddingRight(tpPadRight);
			 	            	    	transTable.addCell(cell);

				            	    	//Column 4 : Amount
			 	            	    	if(SupUsageChargesRepeatSection.getField("Amount")!=null)
				            	    	{
				            	    		cell = new PdfPCell(new Phrase(SupUsageChargesRepeatSection.getField("Amount").asString(), font));
				            	    	}
				            	    	else
				            	    	{
				            	    		cell = new PdfPCell(new Phrase("", font));
				            	    	}
				            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            	    	cell.setBorderWidth(0);
				            	    	cell.setPaddingRight(tpPadRight);
				            	    	transTable.addCell(cell);

				            	    	//Column 5 : Total
				            	    	if(SupUsageChargesRepeatSection.getField("Total")!=null)
				            	    	{
						        	        cell = new PdfPCell(new Phrase(SupUsageChargesRepeatSection.getField("Total").asString(), font));
				            	    	}
				            	    	else
				            	    	{
						        	        cell = new PdfPCell(new Phrase("", font));
				            	    	}
				            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            	    	cell.setPaddingRight(tpPadRight);
				            	    	cell.setBorderWidth(0);
				            	    	transTable.addCell(cell);

				            	    	if(l==subDetailLines-1)
				            	    	{
				            	    		//Add a Blank Line
						            		cell = new PdfPCell(new Phrase("",fontBold));
					    					cell.setColspan(5);
					    					cell.setBorderWidth(0);
					    					transTable.addCell(cell);
				            	    	}

			            	    	}
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Discount & Rebates repeat section
							if(cfiDiscountsAndRebateSection!=null){

								//Discount & Rebates Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Discount & Rebates", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Discount & Rebates Section Part
								StatementSection DiscountsAndRebateRepeatSection = null;
			           			long DetailLines = cfiDiscountsAndRebateSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			DiscountsAndRebateRepeatSection = cfiDiscountsAndRebateSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(DiscountsAndRebateRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(DiscountsAndRebateRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(DiscountsAndRebateRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
			            	    	if(DiscountsAndRebateRepeatSection.getField("Rebate")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(DiscountsAndRebateRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(DiscountsAndRebateRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(DiscountsAndRebateRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(DiscountsAndRebateRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(DiscountsAndRebateRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Service Tax repeat section
							if(cfiServiceTaxSection!=null){

								//Service Tax Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Service Tax (5%)", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Service Tax Section Part
								StatementSection ServiceTaxRepeatSection = null;
			           			long DetailLines = cfiServiceTaxSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			ServiceTaxRepeatSection = cfiServiceTaxSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(ServiceTaxRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	if(ServiceTaxRepeatSection.getField("Rebate")!=null)
			            	    	{
			            	    		cell.setColspan(2);
			            	    	}
			            	    	else
			            	    	{
			            	    		cell.setColspan(3);
			            	    	}
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Rebate
			            	    	if(ServiceTaxRepeatSection.getField("Rebate")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(ServiceTaxRepeatSection.getField("Rebate").asString(), font));
			 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			 	            	    	cell.setBorderWidth(0);
			 	            	    	cell.setPaddingRight(tpPadRight);
			 	            	    	transTable.addCell(cell);
			            	    	}

			            	    	//Column 2 : Amount
			            	    	if(ServiceTaxRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(ServiceTaxRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 3 : Total
			            	    	if(ServiceTaxRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(ServiceTaxRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Extra Section For Details of Changes Start/////////////////

							//Other Charges And Credit repeat section
							if(cfiOtherChargesAndCreditSection!=null){

								//Other Charges And Credit Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Other Charges & Credit", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Other Charges And Credit Section Part
								StatementSection OtherChargesAndCreditRepeatSection = null;
			           			long DetailLines = cfiOtherChargesAndCreditSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			OtherChargesAndCreditRepeatSection = cfiOtherChargesAndCreditSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(OtherChargesAndCreditRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(OtherChargesAndCreditRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(OtherChargesAndCreditRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
			            	    	if(OtherChargesAndCreditRepeatSection.getField("Rebate")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(OtherChargesAndCreditRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(OtherChargesAndCreditRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(OtherChargesAndCreditRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(OtherChargesAndCreditRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(OtherChargesAndCreditRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Advantage Savings repeat section
							if(cfiAdvantageSavingsSection!=null){

								//Advantage Savings Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Advantage Savings", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Advantage Savings Section Part
								StatementSection AdvantageSavingsRepeatSection = null;
			           			long DetailLines = cfiAdvantageSavingsSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			AdvantageSavingsRepeatSection = cfiAdvantageSavingsSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(AdvantageSavingsRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(AdvantageSavingsRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(AdvantageSavingsRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
			            	    	if(AdvantageSavingsRepeatSection.getField("Rebate")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AdvantageSavingsRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(AdvantageSavingsRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AdvantageSavingsRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(AdvantageSavingsRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AdvantageSavingsRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Access Charges repeat section
							if(cfiAccessChargesSection!=null){

								//Access Charges Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Access Charges", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Access Charges Section Part
								StatementSection AccessChargesRepeatSection = null;
			           			long DetailLines = cfiAccessChargesSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			AccessChargesRepeatSection = cfiAccessChargesSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(AccessChargesRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(AccessChargesRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(AccessChargesRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
			            	    	if(AccessChargesRepeatSection.getField("Rebate")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AccessChargesRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(AccessChargesRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AccessChargesRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(AccessChargesRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AccessChargesRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Registration Chargesrepeat section
							if(cfiRegistrationChargesSection!=null){

								//Registration Charges Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Registration Charges", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Registration Charges Section Part
								StatementSection RegistrationChargesRepeatSection = null;
			           			long DetailLines = cfiRegistrationChargesSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			RegistrationChargesRepeatSection = cfiRegistrationChargesSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(RegistrationChargesRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(RegistrationChargesRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(RegistrationChargesRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
			            	    	if(RegistrationChargesRepeatSection.getField("Rebate")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(RegistrationChargesRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(RegistrationChargesRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(RegistrationChargesRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(RegistrationChargesRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(RegistrationChargesRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Extra Section End////////////////////////

							//Add a Blank Line and Line
		            		cell = new PdfPCell(new Phrase("",fontBold));
							cell.setColspan(5);
							cell.setPaddingLeft(tpPadLeft);
							cell.setPaddingRight(tpPadRight);
							cell.setBorderWidth(0.8f);
							cell.setBorder(PdfPCell.BOTTOM);
							transTable.addCell(cell);

							//Total Line Charges section
							if(cfiTotalLineChargesSection!=null){

								//Total Line Charges	- Item
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Total Line Charges", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(0);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(4);
					            transTable.addCell(cell);

					            //Total Current Charges	- Total
					            newParagraph = new Paragraph();
					            newParagraph.add(new Phrase(cfiTotalLineChargesSection.getField("Total").asString(), fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					            cell.setBorder(0);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingRight(tpPadRight);
					            transTable.addCell(cell);
							}
							// Add 5 blank lines testing
//							for (int i = 0; i < 100; i++) {
//								cell = new PdfPCell(new Phrase("",fontBold));
//								cell.setColspan(5);
//								cell.setBorderWidth(0);
//								transTable.addCell(cell);
//							}
						}



						// add the table to the document
						document.add(transTable);

						if(DetailLines2>1 && k!=DetailLines2-1)
						{
							document.newPage();
						}
            		}
				}

            } catch (DocumentException de) {
                System.err.println(de.getMessage());
                de.printStackTrace();
            } catch (Exception ex) {
                System.err.println(ex.getMessage());
                ex.printStackTrace();
            }
        }

    public void addHeader(PdfWriter writer, Document document) {
        try {

        	//Get Image Detail from config
			com.checkfree.isolutions.property.Properties appCfg = com.checkfree.isolutions.property.PropertiesConfig.getApplicationSettings();

			if (appCfg.hasProperty("PdfPrePrintedForm") == false){
				throw new IllegalArgumentException("Image Path not specified!");
			}else{
				String ImagePath = appCfg.getProperty("PdfPrePrintedForm");

				//Add Maxis Image Background
				Image image = Image.getInstance(ImagePath);
				image.setAbsolutePosition(-40, 0);
				image.scalePercent(85,85);
				image.setAlignment(Image.UNDERLYING);
				document.add(image);
			}

        } catch (Exception e) {
            throw new ExceptionConverter(e);
        }
    }

    /**
     * add the footer and header to the document when the page ended
     */
        public void onEndPage(PdfWriter writer, Document document) {

            addHeader(writer, document);
        }

    /**
     *  Release PersistServer resource when the document close
     */
        public void onCloseDocument(PdfWriter writer, Document document) {
            //lhlue 20080427 move PersistServer to PDFDownload Servlet
            //PersistServer.commitTransaction();
            //PersistServer.deactivate();

        }

	/**
     * format the input String and replace the escape charaters
     * @param str string to format
     * @return formated String or blank String if given null String
     */

    public String formatStr (String str) {

        String strFormat=null;

		if (str == null) {

			return "";

		} else {

            strFormat = str.trim();

			// replace escape character
			strFormat = strFormat.replaceAll("&amp;", "&");
			strFormat = strFormat.replaceAll("&quot;", "\"");
			strFormat = strFormat.replaceAll("&apos;", "'");
			strFormat = strFormat.replaceAll("&lt;", "<");
			strFormat = strFormat.replaceAll("&gt;", ">");

			return strFormat;
		}
	}
}
